﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using Survey.Common.Data.Services.HowTos;
using Survey.Entity.Services.HowTos;

namespace Survey.Business.Services.HowTos
{
    [CLSCompliant(false)]
    public class ComplexEntityFilterValidator : FilterValidatorBase<ComplexEntityFilter, long>
    {
        protected override void Init(RuleCollection<ComplexEntityFilter> rules) { base.Init(rules); }
    }
    [CLSCompliant(false)]
    public class ComplexEntityValidator : EntityValidatorBase<ComplexEntity, long, IComplexEntityDao>
    {
        protected override void Init(RuleCollection<ComplexEntity> rules)
        {
            rules.For(entity => entity.ShortName).RequireLengthBetween(2, 10);
            rules.For(entity => entity.VeryLongName).RequireLengthBetween(10, 500);

            rules.Require(entity => entity.SimpleCombo);
            rules.Require(entity => entity.SimpleAsync);

            #region ValueTypes
            rules.For(entity => entity.ByteValue).LimitValueTo(255);
            rules.For(entity => entity.SByteValue).RequireValueBetween(-128, -1);
            rules.For(entity => entity.ByteValueNullable).RequireValueBetween(100, 200); //.AsRequired(); to force the NOT NULL
            rules.For(entity => entity.SByteValueNullable).RequireValueBetween(-50, -20).AllowNull(); // AllowNull is default

            rules.For(entity => entity.ShortValue).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.UShortValue).RequireValueBetween(1000, 5000);
            rules.For(entity => entity.ShortValueNullable).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.UShortValueNullable).RequireValueBetween(1000, 5000);

            rules.For(entity => entity.IntValue).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.UIntValue).RequireValueBetween(1000, 5000);
            rules.For(entity => entity.IntValueNullable).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.UIntValueNullable).RequireValueBetween(1000, 5000);

            rules.For(entity => entity.LongValue).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.ULongValue).RequireValueBetween(1000, 5000);
            rules.For(entity => entity.LongValueNullable).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.ULongValueNullable).RequireValueBetween(1000, 5000);

            rules.For(entity => entity.DecimalValue).RequireValueBetween(-5000, -1000);
            rules.For(entity => entity.DecimalValueNullable).RequireValueBetween(1000, 5000);

            rules.For(entity => entity.FloatValue).RequireValueBetween(1000, 5000);
            rules.For(entity => entity.FloatValueNullable).RequireValueBetween(-5000, -1000);

            rules.For(entity => entity.DoubleValue).RequireValueBetween(1000, 5000);
            rules.For(entity => entity.DoubleValueNullable).RequireValueBetween(-5000, -1000);

            rules.For(entity => entity.ValidFrom).RequireValueBetween(new DateTime(2010, 1, 1), new DateTime(2020, 1, 1));
            rules.For(entity => entity.ValidTo).RequireValueBetween(new DateTime(2020, 1, 1), new DateTime(2025, 1, 1));
            #endregion ValueTypes

            // Code must be valid before IsUnique is called
            rules.For(entity => entity.Code).RequireLengthBetween(3, 50).BreakOnError();
            rules.IsUnique(entity => Dao.Find(entity.ID, new ComplexEntityFilter
            {
                CodeExact = entity.Code
            }));
        }
    }
}
